import moment from 'moment'

const dbModelToViewModel = laf => {
	laf = laf.toObject(laf)
	laf.userName = '隐藏'
	laf.contact = '隐藏'
	if (laf.images.length > 0) {
		laf.image = laf.images[0]
	}
	laf.time = moment(laf.createTime).format('YYYY年MM月DD日 HH:mm:ss')
	return laf
}

const dbModelToViewModels = lafs => {
	return lafs.map(laf => {
		return dbModelToViewModel(laf)
	})
}

const addAuthInfo = (laf, userId) => {
	laf.isMine = userId == laf.userId
	laf.userId = '隐藏'
	return laf
}

const addAuthInfos = (lafs, userId) => {
	return lafs.map(laf => {
		return addAuthInfo(laf, userId)
	})
}

export default {
	dbModelToViewModel: dbModelToViewModel,
	dbModelToViewModels: dbModelToViewModels,
	addAuthInfo: addAuthInfo,
	addAuthInfos: addAuthInfos
}